package com.example.trackcircuitdiagnosis.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.trackcircuitdiagnosis.entity.AlarmEntity;
import com.example.trackcircuitdiagnosis.entity.MonitoringProjectEntity;
import com.example.trackcircuitdiagnosis.mapper.MonitoringProjectMapper;
import com.example.trackcircuitdiagnosis.service.AlarmService;
import com.example.trackcircuitdiagnosis.service.MonitoringProjectService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.*;
/**
 * @author long chen
 * @date 2024-04-03 9:14
 */
@RestController
@CrossOrigin
@RequestMapping("/monitoring_project")
public class MonitoringProjectController {


    @Autowired
    private MonitoringProjectService monitoringProjectService;

    // 新增或者更新
    @PostMapping
    @Operation(description = "更新监控设备信息")
    public boolean save(@RequestBody MonitoringProjectEntity monitoringProjectEntity) {
        return monitoringProjectService.saveOrUpdate(monitoringProjectEntity);
    }

    @DeleteMapping("/{id}")
    @Operation(
            description = "删除监控设备",
            parameters = {
                    @Parameter(name = "mid", description = "要删除的监控信息mid")
            }

    )
    public Boolean delete(@PathVariable Integer id) {
        return monitoringProjectService.removeById(id);
    }

    @PostMapping("/del/batch")
    @Operation(
            description = "批量删除监控设备",
            parameters = {
                    @Parameter(name = "mid", description = "要批量删除的监控设备信息")
            }

    )
    public boolean deleteBatch(@RequestBody List<Integer> ids) {
        return monitoringProjectService.removeByIds(ids);
    }

    @GetMapping
    @Operation(description = "查找全部")
    public List<MonitoringProjectEntity> findAll() {
        return monitoringProjectService.list();
    }

    @GetMapping("/{id}")
    @Operation(
            description = "查找监控设备信息",
            parameters = {
                    @Parameter(name = "id", description = "要查找监控设备信息id")
            }

    )
    public MonitoringProjectEntity findOne(@PathVariable Integer id) {
        return monitoringProjectService.getById(id);
    }

    @GetMapping("/page")
    @Operation(
            description = "分页查询",
            parameters = {
                    @Parameter(name = "pageNum", description = "要查找监控设备信息页数"),
                    @Parameter(name = "pageSize", description = "要查找监控设备信息每一页的数量")
            }

    )
    public Page<MonitoringProjectEntity> findPage(@RequestParam Integer pageNum,
                                      @RequestParam Integer pageSize) {
        QueryWrapper<MonitoringProjectEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("mid");
        return monitoringProjectService.page(new Page<>(pageNum, pageSize), queryWrapper);
    }
}
